package com.tianji.learning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianji.learning.domain.po.NoteUser;
import com.tianji.learning.mapper.NoteUserMapper;
import com.tianji.learning.service.INoteUserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 笔记采用表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-04-25
 */
@Service
public class NoteUserServiceImpl extends ServiceImpl<NoteUserMapper, NoteUser> implements INoteUserService {

    @Override
    public Map<Long, Long> queryusedTimes(List<Long> noteIds) {
        if (noteIds == null || noteIds.isEmpty()){
            return new HashMap<>();
        }

        List<NoteUser> noteUsers = lambdaQuery()
                .in(NoteUser::getNoteId, noteIds)
                .list();
        //利用stream流获取map
        return noteUsers.stream().collect(Collectors.groupingBy(NoteUser::getNoteId, Collectors.counting()));
    }
}
